$("#admininfo_save").click(function () {
    var admininfo = $("#admininfo").serialize();
    $.ajax({
        url: '/admin/updateCache',
        type: 'POST',
        data: admininfo,
        dataType: 'JSON',
        cache: false,
        success: function (json) {
            dshow(json.message);
            if (json.code == 2000) {
                window.location.reload();
            }
        },
        /*error: function (XMLHttpRequest, textStatus, errorThrown) {
         if (XMLHttpRequest.status == 404) {
         parent.layer.msg('请求服务器出错');
         } else if (XMLHttpRequest.status == 500) {
         parent.layer.msg('服务器异常');
         } else {
         parent.layer.msg('服务器未知错误');
         }
         },*/
    });
});
var sub = true;
$("#adminpwd input").blur(function () {
    if ($(this).val().length < 6) {
        $(this).next().text('请输入6位及以上密码');
        sub = false;
    } else {
        sub = true;
    }
});
$("#adminpwd input").focus(function () {
    if ($(this).val().length < 6) {
        $(this).next().text('');
    }
});
$("input[name='rn_password']").blur(function () {
    if (sub) {
        if ($("input[name='new_password']").val() != $("input[name='rn_password']").val()) {
            $(this).next().text('两次输入的密码不一致');
            sub = false;
        }
    }
});
$("input[name='rn_password']").focus(function () {
    sub = true;
});
$("#adminpwd_save").click(function () {
    if (sub) {
        var parms = {
            current_password: $("input[name='current_password']").val(),
            new_password: $("input[name='new_password']").val()
        };
        $.ajax({
            url: '/admin/updatePwd',
            type: 'POST',
            data: parms,
            dataType: 'JSON',
            cache: false,
            success: function (json) {
                dshow(json.message);
                if (json.code == 2000) {
                    window.location.href = '/home';
                }
            }
        });
    }
});
$("#avatar_save").click(function () {
    var path = $("input[name='pic[]']").val();
    $.ajax({
        url: '/admin/avatar',
        type: 'POST',
        data: {path: path},
        dataType: 'JSON',
        cache: false,
        success: function (json) {
            dshow(json.message);
            if (json.code == 2000) {
                window.location.href = '/home';
            }
        }
    });

});
/*
 var imgsrc = $(".file_input").prev().val();
 var oldsrc = $(".thumbnail img").attr('src');
 if (imgsrc) {
 $(".thumbnail img").attr('src', oldsrc + '/' + imgsrc);
 }*/
